package cn.rui.controller;

import cn.rui.constant.MessageConstant;
import cn.rui.entity.QueryPageBean;
import cn.rui.entity.Result;
import cn.rui.service.OrderService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 预约信息
 * @author 徽州大都督
 * @date 2020/8/31
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 分页查询预约信息
     * @param queryPageBean
     * @return
     */
    @PostMapping("findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){


        try {
            List<Map<String, Object>> page = orderService.findPage (queryPageBean);

            return new Result (true, MessageConstant.QUERY_ORDER_SUCCESS,page);
        } catch (Exception e) {
            e.printStackTrace ();
            return new Result (false, MessageConstant.QUERY_ORDER_FAIL);
        }

    }

    /**
     * 根据id删除预约信息
     */
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id")Integer id){
        try {
            orderService.deleteById(id);
            return new Result (true,MessageConstant.DELETE_ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace ();
            return new Result (false,MessageConstant.DELETE_ORDER_FAIL);
        }

    }

    /**
     * 更改到诊状态
     */
    @PutMapping("orderUpdateType/{id}")
    public Result orderUpdateType(@PathVariable("id")Integer id){
        try {
            orderService.orderUpdateType(id);

            return new Result (true,MessageConstant.UPDATE_ORDERTYPE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace ();
            return new Result (false,MessageConstant.UPDATE_ORDERTYPE_FAIL);
        }
    }
}
